package cc.eddic.examinationsystem.domain;

import cc.eddic.examinationsystem.Role;
import cc.eddic.examinationsystem.core.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.List;

@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "t_student")
@Builder
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Student extends BaseEntity {
    public Student(Long employeeNo, String name, Integer gender, String email, String mobile, String password, Role role) {
        this.employeeNo = employeeNo;
        this.name = name;
        this.gender = gender;
        this.email = email;
        this.mobile = mobile;
        this.password = password;
        this.role = role;
    }

    private Long employeeNo;

    @Column(length = 50)
    private String name;

    private Integer gender;

    @Column(length = 50)
    private String email;

    @Column(length = 50)
    private String mobile;

    @Column(length = 60)
    private String password;

    private Role role;


    @JsonIgnore
    @ToString.Exclude
    @OneToMany(mappedBy = "student", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Answer> answers;

    public Student add(Answer answer) {
        answer.setStudent(this);
        answers.add(answer);
        return this;
    }

}
